import 'package:flutter/material.dart';
import 'package:shopping_group/modle/main/ui/lz_preview_image_page.dart';
import 'package:shopping_group/modle/notice/bloc/forum_details_bloc.dart';
import 'package:shopping_group/modle/notice/entity/qry_noticeslst_entity.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/object_util.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/utils.dart';
import 'package:shopping_group/utils/widget_utils.dart';
import 'package:shopping_group/view/image_dailog_view.dart';

class ForumDetailsPage extends StatefulWidget {
  final String id;
  ForumDetailsPage({Key key, @required this.id}) : super(key: key);

  @override
  _ForumDetailsPageState createState() => _ForumDetailsPageState();
}

class _ForumDetailsPageState extends State<ForumDetailsPage> {
  QryNoticesLstEntity _entity = QryNoticesLstEntity();
  List<String> listPhoto = [];
  ForumDetailsBloc _bloc;
  @override
  void initState() {
    super.initState();
    _bloc = ForumDetailsBloc();
    _bloc.initDate.add(this.widget.id);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: WidgetUtils.showAppar(context, '发布详情'),
      body: Container(
        height: double.infinity,
        decoration: BoxDecoration(
          color: Colours.title_white,
        ),
        child: Column(
          children: <Widget>[
            SizedBox(
              height: 8,
            ),
            SingleChildScrollView(
              scrollDirection: Axis.vertical,
              reverse: false,
              padding: EdgeInsets.all(0.0),
              physics: BouncingScrollPhysics(),
              child: _showlistView(),
            ),
          ],
        ),
      ),
    );
  }

  Widget _showlistView() {
    return StreamBuilder(
      stream: _bloc.sendData,
      initialData: _entity,
      builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
        Object object = snapshot.data;
        if (object is QryNoticesLstEntity) {
          _entity = object;
        }
        if (!ObjectUtil.isEmptyList(_entity.lstNoticesFile)) {
          _entity.lstNoticesFile.forEach((element) {
            if (null != element &&
                !ObjectUtil.isEmptyString(element.notisFileType) &&
                'NFT_IMG' == element.notisFileType) {
              listPhoto.add(element.fileUrl);
            }
          });
        }
        return Container(
          decoration: new BoxDecoration(
            color: Colors.white,
          ),
          child: _xunchaItem(),
        );
      },
    );
  }

  Widget _xunchaItem() {
    return Container(
        padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
        // decoration: BoxDecoration(
        //     border: Border.all(color: Colours.themeColor, width: 1.0),
        //     borderRadius: BorderRadius.circular(15),
        //     color: Colours.title_white),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            SizedBox(
              height: 8,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      ObjectUtil.isEmptyString(_entity.createUserHeadImg)
                          ? Icon(
                              Icons.account_circle,
                              size: 64,
                              color: Colours.themeColor,
                            )
                          : WidgetUtils.clipRRectNetWorkImage(_entity.createUserHeadImg, width: 64, height: 64),
                      SizedBox(
                        width: 16,
                      ),
                      Expanded(
                          child: Container(
                              alignment: Alignment.centerLeft,
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.start,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  WidgetUtils.getTextColorView(
                                      _entity.createUserNickname, Colours.text_2222, Dimens.FONT_SIZE_16,
                                      fontweight: FontWeight.w400),
                                  SizedBox(
                                    height: 4,
                                  ),
                                  WidgetUtils.getTextColorView(
                                      _entity.beforeNowTimeLong, Colours.text_2222, Dimens.FONT_SIZE_16,
                                      fontweight: FontWeight.w400),
                                ],
                              ))),
                    ],
                  ),
                ),
                // SizedBox(
                //   width: 2,
                // ),
                // WidgetUtils.getTextColorView(
                //   _entity.fineCt,
                //   Colours.text_2222,
                //   Dimens.FONT_SIZE_12,
                //   textAlign: TextAlign.end,
                // ),
              ],
            ),
            SizedBox(
              height: 8,
            ),
            WidgetUtils.drawDivider(),
            SizedBox(
              height: 8,
            ),
            Container(
              alignment: Alignment.bottomLeft,
              child: WidgetUtils.getTextColorView(_entity.title, Colours.text_2222, Dimens.FONT_SIZE_16,
                  fontweight: FontWeight.w500),
            ),
            SizedBox(
              height: 8,
            ),
            Container(
              alignment: Alignment.centerLeft,
              child: WidgetUtils.getTextColorView(
                _entity.info,
                Colours.text_2222,
                Dimens.FONT_SIZE_14,
              ),
            ),
            SizedBox(
              height: 4,
            ),
            ObjectUtil.isEmptyList(_entity.lstNoticesFile) ? Container() : WidgetUtils.buildGridViewWidget(listPhoto),
            SizedBox(
              height: 4,
            ),
          ],
        ));
  }

  @override
  void dispose() {
    super.dispose();
  }
}
